classdef AbstractPort < MeasurementComponent.MeasurementComponent
    %ABSTRACTPORT �˴���ʾ�йش����ժҪ
    %   �˴���ʾ��ϸ˵��
    
    properties
        device
    end
    
    properties
        last_setting
        current_setting
    end
    
    properties(Access=private)
        isZiPort
    end
    
    methods
        function obj = AbstractPort(device, name, type)
            p=inputParser;
            p.addRequired('device', @(x) isa(x, 'EquipmentControl.ZI.ziMFLI') || ...
                                         isa(x, 'EquipmentControl.SignalSource.TektronixAFG3252') || ...
                                         isa(x, 'EquipmentControl.SignalSource.RigolDG4202'));
            p.addRequired('name', @ischar);
            p.addRequired('type', @(x) ismember(x, {'input', 'output'}));
            p.parse(device, name, type);
            
            obj@MeasurementComponent.MeasurementComponent([device.name '.' name], type);
            obj.device = device;            
            obj.isZiPort = isa(obj.device, 'EquipmentControl.ZI.ziMFLI');
        end
    end
    
    %%
    methods
        function res = viewPortSignal(obj, varargin)
            p=inputParser; p.KeepUnmatched = true;
            p.addParameter('channel2', [],      @(x) isa(x, 'MeasurementComponent.MachineUnit.IOPort.AbstractPort') ...
                                                       || isempty(x) );
            p.addParameter('trig',          [],      @(x) ziScopeTrigInput.test(x) || isempty(x));            
            p.addParameter('name',          'SCOPE', @ischar);
            p.addParameter('domain',        'time',  @(x) ismember(lower(x), {'time', 'frequency'}));
            p.addParameter('shot_number',   1,       @(x) x>0);
            p.addParameter('plot_window',   1,       @(x) ismember(x, [1 2]));
            p.addParameter('rate',          ziEnumScopeSamplingRate.Rate14_6kHz, @ziEnumScopeSamplingRate.test);
            p.addParameter('duration',      0.1,     @(x) x>0);
            p.addParameter('average',       1,       @(x) x>0);
            p.addParameter('slope',         ziEnumTrigEdgeSlope.Positive, @ziEnumTrigEdgeSlope.test);
            p.addParameter('level',         0.0,     @isnumeric);
            p.addParameter('isSegment',     false,   @islogical);
            p.addParameter('isCh1BWlimit',  true,    @islogical);
            p.addParameter('isCh2BWlimit',  true,    @islogical);
            p.parse(varargin{:});
            
            try
                scopeCh2 = p.Results.channel2.getScopeNode();
            catch
                scopeCh2 = [];
            end
            
            if obj.isZiPort
                getSession; zs = sess.getZIServer;
                res = zs.viewScopeSignal(obj.device.device, obj.getScopeNode(), scopeCh2, varargin{:});
            else
                res = [];
            end
        end
    end
    
    %%
    methods(Abstract)
        node = getScopeNode(obj)
        s = getCurrentSetting(obj)
        obj = recoverLastSetting(obj)
        obj = setup(obj, varargin)
        obj = initialize(obj)
    end
end

